<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <script>
        var arr = [1, 2, 3, 4, 2, 5, 6, 2, 7, 2];
        var newArr = [];
        for (var i = 0; i < arr.length; i++) { //length用于计算数组长度
            if (arr[i] != 2) {
                newArr[newArr.length] = arr[i];

            }

        }
        console.log(newArr);
    </script>
</head>

<body>

</body>

</html>